<?php
class MessageModel extends Model {

    protected $_validate = array(
        array('mto', '2,20', '用户名必须为2到20位以内!', 0, 'length', 1),
        array('mto', 'isUser', '不存在此用户名!', 0, 'callback', 1),
        array('title', '2,20', '标题必须为2到20位以内!', 0, 'length', 1),
        array('content', 'require', '内容不得为空!', 0),
        array('content', '1,300', '内容不得超过300位!', 0, 'length', 1),
    );

    protected $_auto = array(
        array('mfrom', 'getFrom', 1, 'callback'),
        array('date', 'createDate', 1, 'function'),
        array('title', 'setFormData', 1, 'function'),
        array('content', 'setFormData', 1, 'function'),
    );

    public function getFrom() {
        return $_COOKIE['user'];
    }

    public function isUser() {
        $user = M('User');
        $to = $_POST['mto'];
        if(!$user->where("name='$to'")->getField('id')) return false;
    }


}

?>